#ifndef AUDIOFILE_HPP_INCLUDED
#define AUDIOFILE_HPP_INCLUDED

#include <QtCore/QObject>
#include <QtCore/QFile>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QString>
#include <QtGui/QImage>
#include "mod/decoder/Decoder.hpp"
#include "mod/decoder/PcmDecoder.hpp"
#include "mod/decoder/MpgDecoder.hpp"
#include "mod/decoder/AacDecoder.hpp"
#include "mod/decoder/VorbisDecoder.hpp"
#include "mod/decoder/FFmpegDecoder.hpp"

#define WAVETRACK_PREVIEW_LENGTH 4096

class AudioFile : public QObject {
        Q_OBJECT
    private:
        unsigned int id;
        char trackPreview[WAVETRACK_PREVIEW_LENGTH];
        bool tagEmpty;
        QFile *file;
        QFileInfo *fileinfo;
        QString artist,album,title,genre,comment,filename,filedir,type,composer;
        unsigned int trackNumber, trackCount,discNumber,discCount,time,year,filesize;
        QImage *cover;
        //Used to know the offset to start audio and to end it
        unsigned int silenceStartEnds, silenceEndStarts;
        unsigned int frequency, channelCount, bitrate, sampleCount, bitsPerSample;
        unsigned long playbackPosition; //in frame
        Decoder *decoder;
    public:
        AudioFile(QString filePath);
        ~AudioFile();
        /// @brief Read tag from audio file if available and get attached picture if available
        void readTag();
        /// @brief Load audio data for playback
        void load();
        /** @brief Get the time at which the first clip in the track starts
        * @return time in seconds, or zero if there are no clips in the track
        */
       unsigned int getStartTime();
       /** @brief Get the time at which the last clip in the track ends, plus
        * recorded stuff
        * @return time in seconds, or zero if there are no clips in the track.
        */
       unsigned int getEndTime();
       unsigned int getRate();
       QString getArtist();
       QString getAlbum();
       QString getTitle();
       QString getGenre();
       QString getComment();
       QString getFilename();
       QString getFiledir();
       QString getComposer();
       unsigned int getTrackNumber();
       unsigned int getTrackCount();
       unsigned int getDiscNumber();
       unsigned int getDiscCount();
       unsigned int getYear();
       unsigned int getTime();
       unsigned int getFilesize();
       unsigned int getFrequency();
       unsigned int getSamplerate();
       unsigned int getChannels();
       unsigned int getBitrate();
       unsigned int getFrames();
       unsigned int getSamples();
       unsigned int getId();
       void setArtist(QString v);
       void setAlbum(QString v);
       void setTitle(QString v);
       void setGenre(QString v);
       void setComment(QString v);
       void setComposer(QString v);
       void setTrackNumber(unsigned int v);
       void setTrackCount(unsigned int v);
       void setDiscNumber(unsigned int v);
       void setDiscCount(unsigned int v);
       void setYear(unsigned int v);
       void setId(unsigned int i);

       //decoding functions
       void prepareDecoding();
       Decoder* getDecoder();
       void endDecoding();
       bool isTagEmpty();
};

#endif
